package im.actor.server.dialog

import java.time.Instant

import im.actor.server.ActorSuite

import scala.collection.immutable.TreeSet

class ReadsSpec extends ActorSuite {

  it should "read right" in spec1

  object UnreadMessage {
    val OrderingAsc = new Ordering[UnreadMessage] {
      override def compare(x: UnreadMessage, y: UnreadMessage): Int =
        if (x.date.isBefore(y.date)) -1
        else if (x.date.isAfter(y.date)) 1
        else 0
    }
  }

  case class UnreadMessage(date: Instant, randomId: Long)

  // reproduces real production case
  def spec1() = {
    val unreadMessages = TreeSet(
      UnreadMessage(Instant.parse("2016-05-05T21:19:53.169Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:20:13.189Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:20:33.209Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:20:53.230Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:21:13.249Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:21:33.270Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:21:53.290Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:22:13.309Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:22:33.329Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:22:53.349Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:23:13.369Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:23:33.389Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:23:53.410Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:24:13.430Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:24:33.449Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:24:53.469Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:25:13.489Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:25:33.510Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:25:53.529Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:26:13.550Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:26:33.569Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:26:53.589Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:27:13.609Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:27:33.630Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:27:53.649Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:28:13.669Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:28:33.690Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:28:53.710Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:29:13.730Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:29:33.758Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:29:53.779Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:30:13.799Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:30:33.819Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:30:53.840Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:31:13.859Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:31:33.880Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:31:53.899Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:32:13.919Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:32:33.939Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:32:53.959Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:33:13.979Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:33:34Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:33:54.019Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:34:14.041Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:34:34.059Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:34:54.079Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:35:14.099Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:35:34.120Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:35:54.140Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:36:14.180Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:36:34.199Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:36:54.219Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:37:14.239Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:37:34.259Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:37:54.279Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:38:14.310Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:38:34.329Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:38:54.350Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:39:14.369Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:39:34.390Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:39:54.409Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:40:14.429Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:40:34.449Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:40:54.469Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:41:14.489Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:41:34.510Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:41:54.529Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:42:14.549Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:42:34.579Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:42:54.629Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:43:14.649Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:43:34.669Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:43:54.689Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:44:14.739Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:44:34.759Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:44:54.779Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:45:14.799Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:45:34.819Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:45:54.850Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:46:14.869Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:46:34.889Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:46:54.910Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:47:14.929Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:47:34.950Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:47:54.969Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:48:14.990Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:48:35.009Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:48:55.029Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:49:15.049Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:49:35.068Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:49:55.093Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:50:15.110Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:50:35.129Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:50:55.149Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:51:15.170Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:51:35.189Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:51:55.220Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:52:15.239Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:52:35.259Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:52:55.279Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:53:15.299Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:53:35.319Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:53:55.339Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:54:15.360Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:54:35.389Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:54:55.409Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:55:15.429Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:55:35.449Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:55:55.471Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:56:15.490Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:56:35.510Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:56:55.529Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:57:15.559Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T21:57:35.579Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T21:57:55.600Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:58:15.620Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:58:35.679Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T21:58:55.699Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:59:15.719Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T21:59:35.740Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T21:59:55.758Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:00:15.780Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:00:35.800Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:00:55.819Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:01:15.839Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:01:35.859Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:01:55.879Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:02:15.900Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:02:35.919Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:02:55.940Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:03:15.958Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:03:35.979Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:03:56Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:04:16.070Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:04:36.089Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:04:56.109Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:05:16.129Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:05:36.148Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:05:56.171Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:06:16.191Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:06:36.219Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:06:56.240Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:07:16.259Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:07:36.279Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:07:56.300Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:08:16.320Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:08:36.339Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:08:56.359Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:09:16.379Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:09:36.399Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:09:56.421Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:10:16.440Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:10:36.459Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:10:56.478Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:11:16.498Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:11:36.520Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:11:56.539Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:12:16.560Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:12:36.580Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:12:56.600Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:13:16.619Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:13:36.639Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:13:56.660Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:14:16.680Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:14:36.699Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:14:56.719Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:15:16.738Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:15:36.759Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:15:56.779Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:16:16.800Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:16:36.819Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:16:56.839Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:17:16.859Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:17:36.879Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:17:56.900Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:18:16.920Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:18:36.940Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:18:56.959Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:19:16.979Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:19:37Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:19:57.029Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:20:17.051Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:20:37.069Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:20:57.090Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:21:17.109Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:21:37.130Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:21:57.150Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:22:17.169Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:22:37.189Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:22:57.209Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:23:17.229Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:23:37.250Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:23:57.270Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:24:17.290Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:24:37.309Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:24:57.329Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:25:17.348Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:25:37.370Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:25:57.389Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:26:17.410Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:26:37.429Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:26:57.449Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:27:17.469Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:27:37.488Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:27:57.509Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:28:17.529Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:28:37.549Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:28:57.569Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:29:17.589Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:29:37.608Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:29:57.629Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:30:17.650Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:30:37.670Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:30:57.688Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:31:17.710Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:31:37.728Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:31:57.749Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:32:17.770Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:32:37.789Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:32:57.808Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:33:17.829Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:33:37.849Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:33:57.869Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:34:17.890Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:34:37.909Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:34:57.928Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:35:17.959Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:35:37.980Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:35:58Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:36:18.019Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:36:38.049Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:36:58.070Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:37:18.088Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:37:38.110Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:37:58.129Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:38:18.150Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:38:38.169Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:38:58.189Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:39:18.208Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:39:38.229Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:39:58.250Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:40:18.270Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:40:38.288Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:40:58.309Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:41:18.329Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:41:38.350Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:41:58.369Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:42:18.390Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:42:38.408Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:42:58.429Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:43:18.449Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:43:38.469Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:43:58.489Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:44:18.510Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:44:38.528Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:44:58.549Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:45:18.569Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:45:38.590Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:45:58.610Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:46:18.630Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:46:38.658Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:46:58.679Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:47:18.699Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:47:38.719Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:47:58.739Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:48:18.760Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:48:38.778Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:48:58.799Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:49:18.819Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:49:38.839Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:49:58.859Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:50:18.879Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:50:38.899Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:50:58.918Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:51:18.939Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:51:38.959Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:51:58.979Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:52:19Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:52:39.018Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:52:59.039Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:53:19.059Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:53:39.079Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:53:59.100Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:54:19.120Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:54:39.139Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:54:59.159Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:55:19.179Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:55:39.200Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:55:59.219Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:56:19.240Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:56:39.258Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:56:59.279Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:57:19.298Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:57:39.319Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:57:59.340Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:58:19.360Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T22:58:39.379Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T22:58:59.400Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T22:59:19.420Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T22:59:39.439Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T22:59:59.489Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T23:00:19.510Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T23:00:39.529Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T23:00:59.548Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T23:01:19.569Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T23:01:39.589Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T23:01:59.609Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T23:02:19.630Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T23:02:39.649Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T23:02:59.669Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T23:03:19.689Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T23:03:39.708Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T23:03:59.729Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T23:04:19.750Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T23:04:39.769Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T23:04:59.790Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T23:05:19.810Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T23:05:39.830Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T23:05:59.850Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T23:06:19.870Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T23:06:39.889Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T23:06:59.910Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T23:07:19.929Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T23:07:39.949Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T23:07:59.969Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T23:08:19.990Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T23:08:40.009Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T23:09:00.028Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T23:09:20.049Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T23:09:40.069Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T23:10:00.090Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T23:10:20.110Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T23:10:40.129Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T23:11:00.149Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T23:11:20.169Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T23:11:40.189Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T23:12:00.209Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T23:12:20.230Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-05T23:12:40.248Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-05T23:13:00.268Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-05T23:13:20.288Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-05T23:13:40.310Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-05T23:14:00.330Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-06T01:27:58.590Z"), 1206618800360478239L),
      UnreadMessage(Instant.parse("2016-05-06T01:28:05.226Z"), 1049493225200461245L),
      UnreadMessage(Instant.parse("2016-05-06T01:28:06.579Z"), 784228647380761753L),
      UnreadMessage(Instant.parse("2016-05-06T01:28:07.558Z"), 8173112782208083217L),
      UnreadMessage(Instant.parse("2016-05-06T01:28:08.504Z"), 6204742633833126734L),
      UnreadMessage(Instant.parse("2016-05-06T03:33:42.078Z"), 605195675516498455L),
      UnreadMessage(Instant.parse("2016-05-06T03:34:03.789Z"), -1830211345866345524L),
      UnreadMessage(Instant.parse("2016-05-06T05:20:26.171Z"), 1249002047020273675L),
      UnreadMessage(Instant.parse("2016-05-06T09:10:52.017Z"), 4259086851540160747L),
      UnreadMessage(Instant.parse("2016-05-06T11:32:56.590Z"), -3175583618477413820L),
      UnreadMessage(Instant.parse("2016-05-06T12:47:12.819Z"), 912764295657230888L),
      UnreadMessage(Instant.parse("2016-05-06T12:47:17.898Z"), 6169732797030877172L),
      UnreadMessage(Instant.parse("2016-05-06T12:47:29.905Z"), 1972930587385065916L),
      UnreadMessage(Instant.parse("2016-05-06T12:48:15.095Z"), 2557534190838172896L),
      UnreadMessage(Instant.parse("2016-05-06T12:48:38.774Z"), -3628654427878364240L),
      UnreadMessage(Instant.parse("2016-05-06T13:21:34.198Z"), 4627642547313149L),
      UnreadMessage(Instant.parse("2016-05-06T14:10:16.774Z"), 5946007128380646619L),
      UnreadMessage(Instant.parse("2016-05-06T14:10:18.944Z"), 9017127962764134453L),
      UnreadMessage(Instant.parse("2016-05-06T14:21:58.712Z"), 4062264501654616765L),
      UnreadMessage(Instant.parse("2016-05-06T17:30:21.927Z"), -3403987135933588616L),
      UnreadMessage(Instant.parse("2016-05-06T17:39:03.168Z"), 5991740629222365866L),
      UnreadMessage(Instant.parse("2016-05-06T18:38:11.971Z"), 7115580044590558664L),
      UnreadMessage(Instant.parse("2016-05-06T18:38:22.769Z"), -3419701542725420508L),
      UnreadMessage(Instant.parse("2016-05-06T18:54:56.686Z"), -6211223795465953694L)
    )(UnreadMessage.OrderingAsc)

    val date = Instant.parse("2016-05-06T18:54:56.686Z")

    val readMessages = unreadMessages.takeWhile(um ⇒ um.date.isBefore(date) || um.date == date)

    val readMessagesIds = unreadMessages.takeWhile(um ⇒ um.date.isBefore(date) || um.date == date).map(_.randomId)

    val newUnreadMessages = unreadMessages.drop(readMessages.size)

    println(s"=== unreadMessages length: ${unreadMessages.size}")
    println(s"=== readMessages length: ${readMessages.size}")
    println(s"=== readMessages ids length: ${readMessagesIds.size}")
    println(s"=== newUnreadMessages length: ${newUnreadMessages.size}")

    readMessages.size shouldEqual unreadMessages.size
    // this one doesn't hold
    //    readMessagesIds.size shouldEqual unreadMessages.size
    newUnreadMessages.size shouldEqual 0
  }

}
